package com.mybatistest.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatistest.mapper.EmpMapper;
import com.mybatistest.pojo.Emp;
import com.mybatistest.pojo.PageBean;
import com.mybatistest.service.EmpService;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class EmpServiceImpl implements EmpService {
    private final EmpMapper empMapper;

    public EmpServiceImpl(EmpMapper empMapper) {
        this.empMapper = empMapper;
    }


    @Override
    public String test() {
        return null;
    }

    @Override
    public PageBean page(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Emp> empList = empMapper.list();
        PageInfo<Emp> p = new PageInfo<>(empList);
        return new PageBean(p.getTotal(),p.getList());
    }
}
